<template>
	<page-meta :page-style="'overflow:'+(popShow?'hidden':'visible')"></page-meta>
	<headassy title="备件详细" :isSearch="false" :isTab="false"></headassy>
	<view class="process-content" :style="'min-height: calc(100vh - ' + (parseInt(system.safeArea.top) + 44) + 'px)'">
		<view class="form" v-for="(item,index) in feeLists" :key="index">
			<view class="">
				费用{{index+1}}
			</view>
			<view class="form-top u-flex-between">
				<view class="">
					费用审核
				</view>
				<u-radio-group active-color="#fd7400" icon-size="36" size="36"
				v-model="item.type"
				 @change="groupChange"
					style="display: flex;justify-content: space-around;">
					<u-radio v-for="(item1, index1) in radiolist1" :key="index1" :label="item1.name" :name="item1.value">{{item1.name}}</u-radio>
				</u-radio-group>
			</view>
			<u--form labelPosition="left" ref="uForm">
				<u-form-item label="申请类型" borderBottom ref="item1" labelWidth="200rpx">
					<view class="align-right" v-if="item.applyType===1">
						向客户收取
					</view>
					<view class="align-right" v-else-if="item.applyType===2">
						向服务商收取
					</view>
					<view class="align-right" v-else-if="item.applyType===0">
						其他
					</view>
				</u-form-item>
				<u-form-item label="费用类型" borderBottom ref="item1" labelWidth="200rpx">
					<view class="align-right">
						{{item.name }}
					</view>
				</u-form-item>
				<u-form-item label="申请金额" borderBottom ref="item1" labelWidth="200rpx">
					<view class="align-right">
						{{item.money }}
					</view>
				</u-form-item>
				<u-form-item label="数量" borderBottom ref="item1" labelWidth="200rpx">
					<view class="align-right">
						{{item.qty }}
					</view>
				</u-form-item>
				<u-form-item label="总金额" borderBottom ref="item1" labelWidth="200rpx">
					<view class="align-right">
						{{item.qty * item.money}}
					</view>
				</u-form-item>
				<u-form-item label="备注" borderBottom ref="item1" labelWidth="200rpx">
					<view class="align-right">
						{{item.remark}}
					</view>
				</u-form-item>
				<u-form-item label="审核备注" borderBottom labelWidth="200rpx">
					<u--input border="none" placeholder="请输入审核备注"></u--input>
				</u-form-item>
			</u--form>
		</view>
		<button class="save-btn" @click="checkFees">审核</button>
	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				radiolist1: [{
						name: '同意',
						value: 0,
						disabled: false
					},
					{
						name: '驳回',
						value: 1,
						disabled: false
					},

				],
				radiovalue1:0,
				id: '',
				feeLists: [],
				feeApply: [],
				custAccId: '',
				acId: '',
				pass: [],
				notPass: [],
				
				popShow: false,			// 禁止穿透
				system: uni.getSystemInfoSync(),
			}
		},
		onLoad(e) {
		
			this.workId = e.workId
			this.id = e.id
			this.custAccId = uni.getStorageSync('custAccid')
			this.acId = uni.getStorageSync('acId')
			this.getFnanceLogList()
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.getPullRefresh()
		},
		methods: {
			// 下拉刷新请求数据
			getPullRefresh(){
				console.clear()
				
				this.getFnanceLogList()
				
			},
			async getFnanceLogList() {
				const res = await uni.$api.money.getFnanceLogList({
					id: this.id
				})
				this.feeLists = res.data.feeLists
				//this.feeLists.forEach()
				this.feeApply = res.data.feeApply
				uni.stopPullDownRefresh()
			},
			async checkFees() {
				this.pass = this.feeLists.filter(i => i.type == 0).map((v, i) => {
					return {
						name: v.name,
						money: v.money,
						remark: v.remark,
						qty: v.qty,
						applyType: v.applyType
					}
				})
				this.notPass = this.feeLists.filter(i => i.type == 1).map((v, i) => {
					return {
						name: v.name,
						money: v.money,
						remark: v.remark,
						qty: v.qty,
						applyType: v.applyType
					}
				})
				let data = {
					zjWorkFeeReview: {
						workId: this.feeApply.workId,
						applyId: this.feeApply.id, //申请表id
						custAccId: this.feeApply.custAccId,
						reviewRemark: "" //审核备注
					},
					pass: this.pass,
					acId: this.acId,
					notPass: this.notPass
				}
				const res = await uni.$api.money.checkFees(data)
				console.log(res, data)
				if (res.code === 0) {
					uni.showToast({
						title: res.msg
					})
					setTimeout(() => {
						uni.navigateBack({
							delta: 1
						})
					}, 1000)
				}
			}
		},

	}
</script>

<style lang="scss">
	/deep/.u-navbar--fixed {
		position: static !important;
	}
	/deep/.u-radio-group--row {
		justify-content: flex-end;
	}
	/deep/.u-radio {
		margin-right: 10rpx;
	}
	
	.flex-around {
		justify-content: space-around;
	}

	.save-btn {
		position: fixed;
		bottom: 20rpx;
		width: calc(100% - 40rpx);
		
		color: #fff;
		height: 50px;
		font-size: 16px;
		border-radius: 10rpx;
		line-height: 50px;
		background-color: #fd7400;
	}

	.address-color {
		color: #505050;
	}

	.process-content {
		background-color: #f5f5f5;
		padding: 20rpx;

		/deep/.u-radio__icon-wrap {
			width: 48rpx !important;
			height: 48rpx !important;
		}

		.top {
			padding: 30rpx 0 28rpx 0;
			padding-left: 32rpx;
			background: $uni-bg-color;
		}

		.radio {
			flex: 1;
		}

		.form {
			background: $uni-bg-color;
			padding: 15px;

			.form-top {
				padding: 30rpx 0 28rpx 0;
				border-bottom: 1px solid #f5f5f5;
			}


		}

		.add {
			background-color: #f5f5f5;
			padding: 30rpx 38rpx 28rpx 0;
			padding-left: 32rpx;
		}
		
		.align-right {
			text-align: right;
		}
	}
</style>